package com.ruoyi.project.his.service.impl;

import com.ruoyi.common.constant.UserConstants;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.project.his.domain.DoctorDept;
import com.ruoyi.project.his.mapper.DoctorDeptMapper;
import com.ruoyi.project.his.service.IDoctorDeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class DoctorDeptService implements IDoctorDeptService {
    @Autowired
    private DoctorDeptMapper doctorDeptMapper;

    /**
     * 按照条件查询科室集合
     * @param doctorDept
     * @return
     */
    @Override
    public List<DoctorDept> selectDoctorDeptList(DoctorDept doctorDept) {
        return doctorDeptMapper.selectDoctorDeptList(doctorDept);
    }

    /**
     * 查询所有科室
     * @return
     */
    @Override
    public List<DoctorDept> selectDoctorDeptAll() {
        return doctorDeptMapper.selectDoctorDeptAll();
    }
    /**
     * 根据主键查询科室详情
     * @param deptId
     * @return
     */
    @Override
    public DoctorDept selectDoctorDeptByDeptId(Integer deptId) {
        return doctorDeptMapper.selectDoctorDeptByDeptId(deptId);
    }
    /**
     * 新增科室
     * @param doctorDept
     * @return
     */
    @Override
    public int insertDoctorDept(DoctorDept doctorDept) {
        return doctorDeptMapper.insertDoctorDept(doctorDept);
    }
    /**
     * 更新科室
     * @param doctorDept
     * @return
     */
    @Override
    public int updateDoctorDept(DoctorDept doctorDept) {
        return doctorDeptMapper.updateDoctorDept(doctorDept);
    }
    /**
     * 批量删除
     * @param deptIds
     * @return
     */
    @Override
    public int deleteDoctorDeptByDeptIds(Integer[] deptIds) {
        return doctorDeptMapper.deleteDoctorDeptByDeptIds(deptIds);
    }
    /**
     * 校验科室名称唯一
     * @param doctorDept
     * @return
     */
    @Override
    public String checkDocketDeptNameUnique(DoctorDept doctorDept) {
        Integer deptId= StringUtils.isNull(doctorDept.getDeptId())?-1:doctorDept.getDeptId();//获取主建
        DoctorDept info=doctorDeptMapper.checkDocketDeptNameUnique(doctorDept.getDeptName());
        if(StringUtils.isNotNull(info)&&!deptId.equals(info.getDeptId())){// 判断查询结果非空，且主键不同。
            return UserConstants.NOT_UNIQUE;
        }
        return UserConstants.UNIQUE;
    }
    /**
     * 校验科室编码唯一
     * @param doctorDept
     * @return
     */
    @Override
    public String checkDocketDeptCodeUnique(DoctorDept doctorDept) {
        Integer deptId = StringUtils.isNull(doctorDept.getDeptId()) ? -1 : doctorDept.getDeptId(); // 获取主键。
        DoctorDept info = doctorDeptMapper.checkDocketDeptCodeUnique(doctorDept.getDeptCode());
        if(StringUtils.isNotNull(info) && !deptId.equals(info.getDeptId())){ // 判断查询结果非空，且主键不同。
            return UserConstants.NOT_UNIQUE; // 不唯一
        }
        return UserConstants.UNIQUE; // 唯一
    }
}
